package edu.washington.cs.sounddetector.server.api.methodresult;

import edu.washington.cs.sounddetector.server.api.MethodResult;
import edu.washington.cs.sounddetector.server.api.method.GetSound;

public class GetSoundResult extends MethodResult<GetSound>
{
    private byte[] sound;
    private long soundId;

    private GetSoundResult(boolean successful, FailureReason reason, byte[] sound, long soundId)
    {
        super(successful, reason);
        this.sound = sound;
        this.soundId = soundId;
    }

    private GetSoundResult()
    {
        this(true, null, null, -1);
    }

    /**
     * @return if {@link #isSuccessful()} is true, returns the sound requested, otherwise returns
     *         null
     */
    public byte[] getSound()
    {
        return sound;
    }

    /**
     * @return if {@link #isSuccessful()} is false, returns the id of the sound that was requested
     *         but does not exist, otherwise returns null
     */
    public long getSoundId()
    {
        return soundId;
    }

    public static GetSoundResult success(byte[] sound)
    {
        return new GetSoundResult(true, null, sound, -1);
    }

    public static GetSoundResult failureSoundDoesNotExist(long soundId)
    {
        return new GetSoundResult(false, FailureReason.SOUND_ID_DOES_NOT_EXIST, null, soundId);
    }
}
